package cn.yj.core.business.service;

import cn.yj.annotation.pagehelper.page.Page;
import cn.yj.cgs.dba.entity.Message;
import cn.yj.cgs.dba.mapper.MessageMapper;
import cn.yj.commons.utils.StringUtils;
import cn.yj.params.check.annotation.Require;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @author 永健
 * @since 2021-06-16 11:30
 */
@Service
public class MessageService extends ServiceImpl<MessageMapper, Message> {

    public Page<Message> pageList(@Require Map<String, Object> params, Page<Message> page) {
        baseMapper.pageList(params, page);
        return page;
    }


    @Override
    public boolean save(@Require Message entity) {
        String userCode = entity.getUserCode();
        if (StringUtils.isNotBlank(userCode)) {
            String[] split = userCode.split(",");
            for (int i = 0; i < split.length; i++) {
                baseMapper.insert(new Message(entity.getContent(),entity.getTitle(),split[i]));
            }
            return true;
        }

        return super.save(entity);
    }
}
